package com.ys.load.util;

import java.io.IOException;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;

public class Test {
	
	//@Autowired
	private HttpClient httpClient;
	
	public void QueryOrder() throws Exception {
		   
		
		  //请求URL
		  URIBuilder uriBuilder = new URIBuilder("https://api.mch.weixin.qq.com/v3/pay/transactions/id/4200000745202011093730578574");
		  uriBuilder.setParameter("mchid", "1698102898");
		 
		  //完成签名并执行请求
		  HttpGet httpGet = new HttpGet(uriBuilder.build());
		  httpGet.addHeader("Accept", "application/json");
		  
		  CloseableHttpResponse response = (CloseableHttpResponse) httpClient.execute(httpGet);
		   
		  try {
		      int statusCode = response.getStatusLine().getStatusCode();
		      if (statusCode == 200) {
		          System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
		      } else if (statusCode == 204) {
		          System.out.println("success");
		      } else {
		          System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
		          throw new IOException("request failed");
		      }
		  } finally {
		      response.close();
		  }
		}
	
	
	
	
	
}
